package com.opennetexam.manager.utils;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * IP工具类
 */
public class IpUtil {

    // 一级模型考试下允许考试的公网IP集合，IP间须以英文分号分隔
    @Value("${allowIpList}")
    private static String allowIpList;

    /**
     * 配置文件获取允许的IP，封装成list返回
     * @return
     */
    public static List<String> getAllowIpList (){
        List<String> allowIPList = new ArrayList<>();
        if(!StringUtils.isEmpty(allowIpList)){
            String[] allowIPArray = allowIpList.split(";");
            for (int i = 0; i< allowIPArray.length ; i++){
                allowIPList.add(allowIPArray[i]);
            }
        }
        return allowIPList;
    }
}
